<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%tlog}}`.
 */
class m230914_023521_create_tlog_table extends Migration
{
    const TABLE_NAME = '{{%tlog}}';

    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $tableOptions = null;
        if ($this->db->driverName === 'mysql') {
            $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE=MyISAM COMMENT="操作日志表"';
        }

        $this->createTable(self::TABLE_NAME, [
            'id' => $this->primaryKey(),
            'aid' => $this->integer()->notNull()->defaultValue(0)->comment('管理员ID'),
            'route' => $this->string()->notNull()->defaultValue('')->comment('路由'),
            'category' => $this->string()->notNull()->defaultValue('')->comment('种类'),
            'prefix' => $this->string()->notNull()->defaultValue('')->comment('客户端'),
            'message' => $this->text()->comment('日志信息'),
            'created_at' => $this->dateTime()->notNull(),
        ], $tableOptions);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable(self::TABLE_NAME);
    }
}
